package com.limbo.showapp.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.limbo.showapp.R;
import com.limbo.showapp.adapter.PictureDisplayAdapter;
import com.limbo.showapp.base.SimpleBaseActivity;
import com.limbo.showapp.bean.PictureBean;
import com.limbo.showapp.constant.AppConstant;
import com.limbo.showapp.util.DisplayUtils;
import com.limbo.showapp.widget.SimpleOptionView;

import java.util.ArrayList;

/**
 * Created by wangqi on 2018/9/7.
 */

public class PictureDisplayActivity extends SimpleBaseActivity {

    private static String PICTURE_NAME = "/%s.jpg";

    private SimpleOptionView simpleTileView;
    private ViewPager viewPager;
    private String source;
    private String title;
    private int page;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_picture_display;
    }

    @Override
    protected void initView() {
        title = getIntent().getStringExtra("title");
        source = getIntent().getStringExtra("source");
        page = getIntent().getIntExtra("page", 0);

        simpleTileView = findViewById(R.id.simpleTileView);
        viewPager = findViewById(R.id.view_pager);

        DisplayUtils.initAfterSetContentView(this, simpleTileView);
    }

    @Override
    protected void initData() {
        //setData
        simpleTileView.setTitle(title);
        String path = AppConstant.Url.BASE_URL + source + PICTURE_NAME;

        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < page; i++) {
            list.add(String.format(path, i + 1));
        }

        viewPager.setAdapter(new PictureDisplayAdapter(this, list));
        viewPager.setCurrentItem(0);
    }

    public static void OpenActivity(Context context, String title, String source, int page) {
        Intent intent = new Intent(context, PictureDisplayActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("source", source);
        intent.putExtra("page", page);
        context.startActivity(intent);
    }
}
